import { Component, OnInit } from '@angular/core';
import { JsonApiService } from "app/core/api/json-api.service"; //http请求配置引入
import { config } from '../../../shared/smartadmin.config';
import { Router, ActivatedRoute } from "@angular/router"; //路由引入

declare var $: any;
@Component({
	selector: 'sa-carCode2',
	templateUrl: './carCode2.component.html',
})
export class CarCode2Component implements OnInit {

	tableData: any = []; //table数据
	totalCount: number = 0; //分页总条数
	curPage: number = 1; //分页当前页
	pageSize: number = 10; //内置的分页每页条数
	searchKey: string = ''; //搜索keyword

	carNumber = ''; //车牌号码
	deviceId: string = ''; //设备ID
	companyName: string = ''; //公司名称
	companyId: string = '';
	searchVal:string='';
	startTime: string = ''; //开始时间
	endTime: string = ''; //结束时间
	constructor(private jsonApiService: JsonApiService, private router: Router, private activatedRoute: ActivatedRoute) {}
	getSelectTableTime(time) {
		this.startTime = time.startTime;
		this.endTime = time.endTime;
	}

	ngOnInit() {
		this.load()
	}

	//加载表格数据
	load() {
		var postData = {
			pageSize: this.pageSize,
			nowPage: this.curPage,
			parameters: {
				companyId: this.companyId,
				deviceId: this.deviceId,
				searchKey: this.searchVal,
			}
		}
		let reqdata = 'gridPager=' + JSON.stringify(postData);
		this.jsonApiService.http("QRcodeCarManage/QRcodeCarManage.html", reqdata).subscribe(data => {
			this.tableData = data.exhibitDatas;
			this.totalCount = data.recordCount;
		})
	}
	//删除
	delRowData(row){
		this.jsonApiService.confirm_message("此操作将永久删除数据,确认要删除?").then(()=>{
			let reqdata = 'id='+row.id;
			this.jsonApiService.http("QRcodeCarManage/deleteLYCar.html", reqdata).subscribe(data => {
				this.jsonApiService.message(data.message);
				this.load();
			})
		})
	}
	downloadCode2(row) {
		let parameters = {
			carNumber:row.carNumber,
			deviceId:row.deviceId,
		};
		let paramsName='params';
		let _url=config.BaseURL + 'QRcodeCarManage/downloadQRcode.html';
		common.exprotDataFile(parameters,paramsName,_url);
	}

	//刷新
	refresh() {
		this.load();
	}
	//查询
	search_data() {
		this.searchKey = common.stringTrim(this.searchKey);
		this.load();
	}
	//模糊搜索
	table_search() {
		this.search_data();
	}
	//分页回调
	paginate(e) {
		this.curPage = e.page + 1;
		this.pageSize = e.rows;
		this.load();
	}
	ngOnDestroy() {
		document.onclick = null;
	}
	//公司选中回调
	companySelected(data){
		this.companyId = data.companyId;
		this.companyName = data.companyName;
		this.deviceId = data.deviceId;
		this.carNumber = data.carNumber;
	}
}